package com.briup.day24;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author ThinkBook
 */
public class Test01_Copy {
    public static void main(String[] args) {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        long start = System.currentTimeMillis();
        long end = 0L;
        try {
            // 获取文件输入流
            fis = new FileInputStream("src/file/test01.wmv");
            // 获取文件输出流
            fos = new FileOutputStream("src/file/test02.wmv");
            // fis.read();//一个字节一个字节读取
            // fis.read(byte[] )
            byte[] buf = new byte[1024];
            int len = -1 ;
            while ((len = fis.read(buf)) != -1) {
                // 读取的字节数组通过输出流写到磁盘
                fos.write(buf, 0, len);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            end = System.currentTimeMillis();
            System.out.println("一共耗时：" + (end - start) + "毫秒");
        }
    }
}
